﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reviewer.Entities;
using System.Data;
using System.Collections.ObjectModel;
using System.Globalization;
using Reviewer.Utilities.Data;
using MySql.Data.MySqlClient;
using Reviewer.Data.Bases;
using System.Data.SqlClient;

namespace Reviewer.Data
{
    /// <summary>
    /// News Repository
    /// </summary>
    [CLSCompliant(false)]
    public class FrontPagePostImageRepository : RepositoryCrudBase<FrontPagePostImage, Int32>
    {
        #region fields (private)
        private const string TABLE_NAME = "V2_ForsidePostImg";
        private static readonly CrudColumnInfo columnId = new CrudColumnInfo(0, "Id", MySqlDbType.Int32, true, false, false, true);
        private static readonly CrudColumnInfo columnFileName = new CrudColumnInfo(1, "Filnavn", MySqlDbType.VarChar, 255, false, false, true);
        private static readonly CrudColumnInfo columnTags = new CrudColumnInfo(2, "Tags", MySqlDbType.VarChar, 255, false, false, true);
        #endregion

        #region methods (public)

        #endregion

        #region methods (protected)
        internal override CrudColumnInfo[] Columns
        {
            get
            {
                return new CrudColumnInfo[]{
                    FrontPagePostImageRepository.columnId
                    , FrontPagePostImageRepository.columnFileName
                    , FrontPagePostImageRepository.columnTags};
            }
        }

        protected override string TableName
        {
            get { return FrontPagePostImageRepository.TABLE_NAME; }
        }

        internal override object ColumnToValue(CrudColumnInfo info, FrontPagePostImage item)
        {
            if (info != null && item != null)
            {
                if (info.Equals(FrontPagePostImageRepository.columnId)) return item.Id;
                else if (info.Equals(FrontPagePostImageRepository.columnFileName)) return item.FileName;
                else if (info.Equals(FrontPagePostImageRepository.columnTags)) return item.Tags;
            }
            return null;
        }

        protected override FrontPagePostImage BuildItemFromReader(IDataReader reader)
        {
            FrontPagePostImage item = new FrontPagePostImage();
            if (reader != null)
            {
                item.Id = DataReaderUtility.GetValue(reader, reader.GetOrdinal(FrontPagePostImageRepository.columnId.Name), 0);
                item.FileName= DataReaderUtility.GetValue(reader, reader.GetOrdinal(FrontPagePostImageRepository.columnFileName.Name), String.Empty);
                item.Tags = DataReaderUtility.GetValue(reader, reader.GetOrdinal(FrontPagePostImageRepository.columnTags.Name), String.Empty);
            }
            return item;
        }
        #endregion
    }
}
